﻿using System;
using System.Xml;
using System.Text;
using System.Collections.Generic;
using InfoCenter.Agent.Helpers;
using System.Data;
using System.IO;
using System.Drawing;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace SXDXClient
{

    public struct TSystemTime
    {
        public ushort wYear;
        public ushort wMonth;
        public ushort wDayOfWeek;
        public ushort wDay;
        public ushort wHour;
        public ushort wMinute;
        public ushort wSecond;
        public ushort wMilliseconds;
    }


    public struct TTimeStamp
    {
        public Int32 time;
        public Int32 date;
    }
    public partial class frmMain : Form
    {
        public string Log
        {
            get
            {
                return txtLog.Text;
            }
            set
            {
                txtLog.Text = value;
            }
        }
        private const int WM_LED_NOTIFY = 1025;
        LEDClient LEDClient = new LEDClient();
        int nLEDID = 1;
        string result = "";
        int x = 0;
        int y = 0;
        int width = 256;
        int height = 64;
        string font = "";
        Int32 inmethod = 1;
        Int32 inspeed = 1;
        Int32 outmethod = 1;
        Int32 outspeed = 1;
        Int32 stopmethod = 0;
        Int32 stopspeed = 1;
        Int32 stoptime = 1000;
        int pwidth = 256;
        int pheight = 256;
        public frmMain()
        {
            InitializeComponent();
        }



        public void EncodeDateTime(ref TSystemTime t, ushort year, ushort month, ushort day, ushort hour, ushort minute, ushort second, ushort milliseconds)
        {
            t.wYear = year;
            t.wMonth = month;
            t.wDay = day;
            t.wHour = hour;
            t.wMinute = minute;
            t.wSecond = second;
            t.wMilliseconds = milliseconds;
        }

        public int MonthDays(int ryear, int month)
        {
            int r = 0;
            switch (ryear)
            {
                case 0:
                    switch (month)
                    {
                        case 0:
                        case 2:
                        case 4:
                        case 6:
                        case 7:
                        case 9:
                        case 11:
                            r = 31;
                            break;
                        case 3:
                        case 5:
                        case 8:
                        case 10:
                            r = 30;
                            break;
                        case 1:
                            r = 28;
                            break;
                    }
                    break;
                case 1:
                    switch (month)
                    {
                        case 0:
                        case 2:
                        case 4:
                        case 6:
                        case 7:
                        case 9:
                        case 11:
                            r = 31;
                            break;
                        case 3:
                        case 5:
                        case 8:
                        case 10:
                            r = 30;
                            break;
                        case 1:
                            r = 29;
                            break;
                    }
                    break;
            }
            return r;
        }

        public void SystemTimeToTimeStamp(ref TSystemTime itime, ref TTimeStamp otime)
        {
            Int32 i, y, m, d;

            y = itime.wYear - 1;
            for (m = 0, d = itime.wYear; d > 100; d -= 100, m++) ;

            if (((itime.wYear & 3) == 0) && ((m & 3) == 0 || (d != 0))) d = 1;
            else d = 0;

            otime.date = itime.wDay;
            for (i = 1; i <= itime.wMonth - 1; i++) otime.date += MonthDays(d, i - 1);
            otime.date += y * 365 + (y >> 2) - (y / 100) + (y / 400);

            otime.time = itime.wHour * 60 * 60000 + itime.wMinute * 60000 + itime.wSecond * 1000 + itime.wMilliseconds;
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            Logger.Debug("Start listener thread");
            nLEDID = 1;
            //cmbDevType.SelectedIndex = 1;
            //cmbBaudRate.SelectedIndex = 0;
            int reset = 0;
            //reset = 1;
            LEDClient.LED_Startup(reset);
            //LEDSender.Do_LED_CloseDeviceOnTerminate(1);
        }

        private void frmMain_FormClosed(object sender, FormClosedEventArgs e)
        {
            
        }

        private void btnPowerOn_Click(object sender, EventArgs e)
        {
            StartUpAndShowIP(nLEDID);
        }

        private void btnPowerOff_Click(object sender, EventArgs e)
        {
            LEDClient.SwithPower(nLEDID, 0, 0);
        }

        private void btnGetPower_Click(object sender, EventArgs e)
        {
            result = LEDClient.LED_GetPower(nLEDID);
            Log = result;
        }

        private void btnSetBright_Click(object sender, EventArgs e)
        {
            LEDClient.LED_SetBright(nLEDID, 1);
        }

        private void btnGetBright_Click(object sender, EventArgs e)
        {
            result = LEDClient.LED_GetBright(nLEDID);
            Log = result;
        }

        private void btnAdjustTime_Click(object sender, EventArgs e)
        {
            result = LEDClient.LED_AdjustTime(nLEDID);
        }

        private void btnGetDisplay_Click(object sender, EventArgs e)
        {
            result = LEDClient.LED_GetPlayContent(nLEDID);
        }

        private void btnChapterEx_Click(object sender, EventArgs e)
        {
            TTimeStamp fromtime = new TTimeStamp();
            TTimeStamp totime = new TTimeStamp();
            TSystemTime T = new TSystemTime();


            result = LEDClient.LED_MakeRoot(nLEDID, "ROOT_PLAY", "COLOR_MODE_DOUBLE", "SURVIVE_ALWAYS");
            ushort K = System.Convert.ToUInt16(result);
            //此例程，按照每周周一、周三的8点到13点播放该节目
            //开始时间 08:00:00  当按照每日时间播放时，fromtime和totime中的日期部分将被忽略掉 
            EncodeDateTime(ref T, 2013, 1, 1, 14, 40, 0, 0);
            SystemTimeToTimeStamp(ref T, ref fromtime);
            //结束时间 13:00:00
            EncodeDateTime(ref T, 2013, 1, 1, 14, 42, 0, 0);
            SystemTimeToTimeStamp(ref T, ref totime);
            LEDClient.LED_AddChapterEx(nLEDID, K, 30000, "WAIT_CHILD", 1, 127, fromtime.time, fromtime.date, totime.time, totime.date);
            LEDClient.LED_AddRegion(nLEDID, K, 0, 0, 128, 32, 0);
            LEDClient.LED_AddLeaf(nLEDID, K, 10000, "WAIT_CHILD");
            //第1页面
            //LEDClient.LED_AddTextEx(nLEDID, num, 0, 0, 128, 32, 1, 0, "开始播放!", "宋体", 21, 0xff, "WFS_NONE", 1, 0, 0, 0, 6, 5, 1, 5, 0, 0, 3000);
            LEDClient.LED_AddText(nLEDID, K, 0, 0, 288, 64, 1, 0, "开始播放", "宋体", 12, 0xff, "WFS_NONE", 1, 0, 1, 1, 1, 1, 0, 1, 3);
            //自动换行的文字

            //此例程，按照每周周一、周三的8点到13点播放该节目
            //开始时间 08:00:00  当按照每日时间播放时，fromtime和totime中的日期部分将被忽略掉 
            EncodeDateTime(ref T, 2013, 1, 1, 14, 43, 0, 0);
            SystemTimeToTimeStamp(ref T, ref fromtime);
            //结束时间 13:00:00
            EncodeDateTime(ref T, 2013, 1, 1, 15, 55, 0, 0);
            SystemTimeToTimeStamp(ref T, ref totime);
            //LEDSender.Do_AddChapterEx(K, 30000, LEDSender.WAIT_CHILD, 1, (ushort)(LEDSender.CS_MON + LEDSender.CS_WED), ref fromtime, ref totime);
            LEDClient.LED_AddChapterEx(nLEDID, K, 30000, "WAIT_CHILD", 1, 127, fromtime.time, fromtime.date, totime.time, totime.date);
            LEDClient.LED_AddRegion(nLEDID, K, 0, 0, 128, 32, 0);

            //第1页面
            LEDClient.LED_AddLeaf(nLEDID, K, 10000, "WAIT_CHILD");
            //自动换行的文字
            //LEDClient.LED_AddTextEx(nLEDID, num, 0, 0, 128, 32, 1, 0, "多谢观赏", "宋体", 21, 0xff, "WFS_NONE", 1, 0, 0, 0, 6, 5, 1, 5, 0, 0, 3000);
            LEDClient.LED_AddText(nLEDID, K, 0, 0, 288, 64, 1, 0, "多谢观赏", "宋体", 12, 0xff, "WFS_NONE", 1, 0, 1, 1, 1, 1, 0, 1, 3);
            LEDClient.LED_SendToScreen(nLEDID, K, 1);
        }

        private void btnText_Click(object sender, EventArgs e)
        {
            string text = "";
            x = 0;
            y = 0;
            width = 288;
            height = 32;
            uint time=1000;
            result = LEDClient.LED_MakeRoot(nLEDID, "ROOT_PLAY", "COLOR_MODE_DOUBLE", "SURVIVE_ALWAYS");
            int K = System.Convert.ToInt32(result);
            LEDClient.LED_AddChapter(nLEDID, K, 1000, "WAIT_USE_TIME");
            LEDClient.LED_AddRegion(nLEDID, K, x, y, width, height, 0);
            LEDClient.LED_AddLeaf(nLEDID, K, 1000, "WAIT_CHILD");

            text = LEDClient.LED_GetText(24);
            LEDClient.LED_AddText(nLEDID, K, x, y, width, height, 1, 0,"X~!@#$*&ABCDEFG()杭州地铁二号线欢迎您", "宋体", 12, 0xff, "WFS_NONE", 1, 0, 1, 1, 1, 1, 0, 1, 3);
            //LEDClient.LED_AddText(nLEDID, K, x, y, width, height, 1, 0, "时间", "宋体", 12, 0xff, "WFS_NONE", 1, 0, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime);

            /* x = 0; y = 16; width = 288; height = 16;
              inmethod = 2;
            inspeed = 4;
            LEDClient.LED_AddRegion(nLEDID, K, x, y, width, height, 0);
            LEDClient.LED_AddLeaf(nLEDID, K, 5 * time, "WAIT_CHILD");
            
          
            LEDClient.LED_AddText(nLEDID, K, x, y, width, height, 1, 0, "杭州地铁二号线欢迎您", "宋体", 12, 0xffff, "WFS_NONE", 1, 0, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime);
           LEDClient.LED_AddLeaf(nLEDID, K, 5 * time, "WAIT_CHILD");
            LEDClient.LED_AddText(nLEDID, K, x, y, width, height, 1, 0, "武林广场站E出入口", "宋体", 12, 0xff00, "WFS_NONE", 1, 0, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime);

            inmethod = 4; inspeed = 5;
            LEDClient.LED_AddLeaf(nLEDID, K, 5 * time, "WAIT_CHILD");
            text = LEDClient.LED_GetText(23);
            LEDClient.LED_AddText(nLEDID, K, x, y, width, height, 1, 0, text, "宋体", 12, 0xff00, "WFS_NONE", 1, 0, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime);
            */
            LEDClient.LED_SendToScreen(nLEDID, K, 1);
        }
        private void Test2()
        {
            string text = "";
            int K = 0;
            Log = "Start data";
            result = LEDClient.LED_MakeRoot(nLEDID, "ROOT_PLAY", "COLOR_MODE_DOUBLE", "SURVIVE_ALWAYS");
            K = System.Convert.ToInt32(result);
            x = 0; y = 0; width = 256; height = 32;
            uint time = 1000;
            LEDClient.LED_AddChapter(nLEDID, K, 20 * time, "WAIT_CHILD");
            x = 0; y = 16; width = 288; height = 16;
            LEDClient.LED_AddRegion(nLEDID, K, x, y, width, height, 0);
            LEDClient.LED_AddLeaf(nLEDID, K, 20 * time, "WAIT_CHILD");
            LEDClient.LED_AddText(nLEDID, K, x, y, width, height, 1, 0, "时间", "宋体", 12, 0xff, "WFS_NONE", 1, 0, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime);
            /*
            x = 0; y = 48; width = 288; height = 16;
            LEDClient.LED_AddRegion(nLEDID, K, x, y, width, height, 0);
            LEDClient.LED_AddLeaf(nLEDID, K, 5 * time, "WAIT_CHILD");
            inmethod = 2;
            inspeed = 4;
            LEDClient.LED_AddText(nLEDID, K, x, y, width, height, 1, 0, "杭州地铁二号线欢迎您", "宋体", 12, 0xffff, "WFS_NONE", 1, 0, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime);
            LEDClient.LED_AddLeaf(nLEDID, K, 5 * time, "WAIT_CHILD");
            LEDClient.LED_AddText(nLEDID, K, x, y, width, height, 1, 0, "武林广场站E出入口", "宋体", 12, 0xff00, "WFS_NONE", 1, 0, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime);

            inmethod = 4; inspeed = 5;
            LEDClient.LED_AddLeaf(nLEDID, K, 5 * time, "WAIT_CHILD");
            text = LEDClient.LED_GetText(23);
            LEDClient.LED_AddText(nLEDID, K, x, y, width, height, 1, 0, text, "宋体", 12, 0xff00, "WFS_NONE", 1, 0, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime);
            */
            result = LEDClient.LED_SendToScreen(nLEDID, K, 1);
            Log = result;

        }
        private void Test1()
        { 
            string text = "";
            int K = 0;
            Log = "Start data";
            result = LEDClient.LED_MakeRoot(nLEDID, "ROOT_DOWNLOAD", "COLOR_MODE_DOUBLE", "SURVIVE_ALWAYS");
            K = System.Convert.ToInt32(result);
            x = 0; y = 0; width = 288; height = 16;
            uint time = 1000;
            LEDClient.LED_AddChapter(nLEDID, K, 20 * time, "WAIT_CHILD");
            x = 0; y = 0; width = 288; height = 16;
            LEDClient.LED_AddRegion(nLEDID, K, x, y, width, height, 0);
            LEDClient.LED_AddLeaf(nLEDID, K, 20 * time, "WAIT_CHILD");
            LEDClient.LED_AddDateTimeEx(nLEDID, K, x, y, width, height, 1, 0, 0, "宋体", 12, 0xffff, "WFS_NONE", 0, 0, 0, 0, "#y年#m月#d日 星期#w #h时#n分#s秒");
         
            x = 0; y = 16; width = 288; height = 32;
            LEDClient.LED_AddRegion(nLEDID, K, x, y, width, height, 0);
            LEDClient.LED_AddLeaf(nLEDID, K, 10 * time, "WAIT_CHILD");
            text = LEDClient.LED_GetText(23);
            text = "杭州地铁二号线欢迎您)";
            inmethod = 1;
            inspeed = 1;
            LEDClient.LED_AddText(nLEDID, K, 0, 0, width, height, 1, 0, text, "宋体", 24, 0xff, "WFS_NONE", 1, 0, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime);
            LEDClient.LED_AddLeaf(nLEDID, K, 10 * time, "WAIT_CHILD");
            text = "武林广场站 E出入口";
            inmethod = 1; inspeed = 1;
            LEDClient.LED_AddText(nLEDID, K, 0, 0, width, height, 1, 0, text, "宋体", 24, 0xff, "WFS_NONE", 1, 0, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime);

            x = 0; y = 48; width = 288; height = 16;
            LEDClient.LED_AddRegion(nLEDID, K, x, y, width, height, 0);
            LEDClient.LED_AddLeaf(nLEDID, K, 10 * time, "WAIT_CHILD");
            text = LEDClient.LED_GetText(23);            
            inmethod = 2;
            inspeed = 1;
            LEDClient.LED_AddText(nLEDID, K, 0, 0, width, height, 1, 0, text, "宋体", 12, 0xff, "WFS_NONE", 1, 0, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime);
 

            Log = "Start Sending data";
            result = LEDClient.LED_SendToScreen(nLEDID, K, 1);
            Log = result;
        }
        private void btnTextNoStruct_Click(object sender, EventArgs e)
        {
            Test1();
            return;
            string text = "";
            int K = 0;
            Log = "Start data";
            result = LEDClient.LED_MakeRoot(nLEDID, "ROOT_DOWNLOAD", "COLOR_MODE_DOUBLE", "SURVIVE_ALWAYS");
            K = System.Convert.ToInt32(result);
            x = 0; y = 0; width = 128; height = 32;
            uint time = 1000;
            LEDClient.LED_AddChapter(nLEDID, K, 20 * time, "WAIT_CHILD");
            x = 0; y = 0; width = 80; height = 32;
            LEDClient.LED_AddRegion(nLEDID, K, x, y, width, height, 0);
            LEDClient.LED_AddLeaf(nLEDID, K, 20 * time, "WAIT_CHILD");
            LEDClient.LED_AddPicture(nLEDID, K, 0, 0, pheight, pheight, 1, 0, "A1.jpg", 0, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime);

            x = 91; y = 0; width = 80; height = 64;
            LEDClient.LED_AddRegion(nLEDID, K, x, y, width, height, 0);
            LEDClient.LED_AddLeaf(nLEDID, K, 5 * time, "WAIT_CHILD");
            inmethod = 2;
            inspeed = 4;
            LEDClient.LED_AddPicture(nLEDID, K, 0, 0, pwidth, pheight, 1, 0, "A2.jpg", 0, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime);
            inmethod = 4;
            inspeed = 5;
            LEDClient.LED_AddLeaf(nLEDID, K, 5 * time, "WAIT_CHILD");
            LEDClient.LED_AddPicture(nLEDID, K, 0, 0, pwidth, pheight, 1, 0, "A3.jpg", 0, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime);

            x = 161; y = 0; width = 256; height = 64;
            LEDClient.LED_AddRegion(nLEDID, K, x, y, width, height, 0);
            LEDClient.LED_AddLeaf(nLEDID, K, 10 * time, "WAIT_CHILD");
            LEDClient.LED_AddMovie(nLEDID, K, 0, 0, pwidth, pheight, 1, 0, "B5.gif", 0);

            x = 0; y = 16; width = 128; height = 32;
            LEDClient.LED_AddRegion(nLEDID, K, x, y, width, height, 0);
            LEDClient.LED_AddLeaf(nLEDID, K, 10 * time, "WAIT_CHILD");
            text = LEDClient.LED_GetText(23);
            inmethod = 2;
            inspeed = 1;
            LEDClient.LED_AddText(nLEDID, K, x, y, width, height, 1, 0, text, "宋体", 12, 0xff00, "WFS_NONE", 1, 0, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime);


            x = 30; y = 10; width = 256; height = 32;
            LEDClient.LED_AddRegion(nLEDID, K, x, y, width, height, 0);
            for (int iID = 0; iID < 22; iID++)
            {
                if (iID < 3)
                {
                    font = LEDClient.LED_GetFont(iID);
                }
                LEDClient.LED_AddLeaf(nLEDID, K, time, "WAIT_CHILD");
                text = LEDClient.LED_GetText(iID);
                LEDClient.LED_AddText(nLEDID, K, x, y, width, height, 1, 0, font + ": 尺寸" + System.Convert.ToInt16(12 + iID) + "--" + text, font, 12 + iID, 0xff, "WFS_NONE", 1, 0, iID, 1, 1, 1, 0, 1, stoptime);

                LEDClient.LED_AddLeaf(nLEDID, K, time, "WAIT_CHILD");
                text = LEDClient.LED_GetText(iID);
                LEDClient.LED_AddText(nLEDID, K, x, y, width, height, 1, 0, font + ": 尺寸" + System.Convert.ToInt16(12 + iID) + "--" + text, font, 12 + iID, 0xff00, "WFS_NONE", 1, 0, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime);
            }


            Log = "Start Sending data";
            result = LEDClient.LED_SendToScreen(nLEDID, K, 1);
            Log = result;
        }

        private void btnDib_Click(object sender, EventArgs e)
        {


            result = LEDClient.LED_MakeRoot(nLEDID, "ROOT_PLAY", "COLOR_MODE_DOUBLE", "SURVIVE_ALWAYS");
            int num = System.Convert.ToInt32(result);
            LEDClient.LED_AddChapter(nLEDID, num, 30000, "WAIT_CHILD");
            LEDClient.LED_AddRegion(nLEDID, num, 0, 0, 128, 32, 0);

            LEDClient.LED_AddLeaf(nLEDID, num, 10000, "WAIT_CHILD");
            LEDClient.LED_AddWindow(nLEDID, num, 0, 0, 128, 32, 1, 0, "A1.jpg", 128, 32, 0, 1, 1, 1, 1, 1, 0, 3000);
            LEDClient.LED_SendToScreen(nLEDID, num, 1);
        }

        private void btnPicFile_Click(object sender, EventArgs e)
        {
            string text = "";
            x = 0;
            y = 0;
            width = 256;
            height = 256;

            result = LEDClient.LED_MakeRoot(nLEDID, "ROOT_PLAY", "COLOR_MODE_DOUBLE", "SURVIVE_ALWAYS");
            int K = System.Convert.ToInt32(result);

            LEDClient.LED_AddChapter(nLEDID, K, 1000, "WAIT_USE_TIME");
            LEDClient.LED_AddRegion(nLEDID, K, x, y, width, height, 0);

            LEDClient.LED_AddLeaf(nLEDID, K, 1000, "WAIT_CHILD");

            text = LEDClient.LED_GetText(4);
            LEDClient.LED_AddText(nLEDID, K, x, y, width, height, 1, 0, text, "宋体", 12, 0xff, "WFS_NONE", 1, 0, 1, 1, 1, 1, 0, 1, 3);
            /*
             LEDClient.LED_AddChapter(nLEDID, K, 1000, "WAIT_USE_TIME");
             LEDClient.LED_AddRegion(nLEDID, K, x, y, width, height, 0);
             LEDClient.LED_AddLeaf(nLEDID, K, 1000, "WAIT_CHILD");
             text = LEDClient.LED_GetText(4);
             LEDClient.LED_AddText(nLEDID, K, x, y, width, height, 1, 0, text, "宋体", 12, 0xff00, "WFS_NONE", 1, 0, 1, 1, 1, 1, 0, 1, 3);
             */
            LEDClient.LED_AddChapter(nLEDID, K, 5000, "WAIT_USE_TIME");
            LEDClient.LED_AddRegion(nLEDID, K, x, y, width, height, 0);
            LEDClient.LED_AddLeaf(nLEDID, K, 5000, "WAIT_CHILD");
            //LEDClient.LED_AddWindow(nLEDID, K, x, y, width, height, 1, 0, "A1.jpg", 256, 128, 0, 1, 1, 1, 1, 1, 0, 1000); 
            //LEDClient.LED_AddPicture(nLEDID, K, x, y, width, height, 1, 0, "A1.jpg",  0, 1, 1, 1, 1, 1, 0, 1000);
            LEDClient.LED_AddMovie(nLEDID, K, x, y, width, height, 1, 0, "B5.gif", 0);
            LEDClient.LED_SendToScreen(nLEDID, K, 1);
        }

        private void btnString_Click(object sender, EventArgs e)
        {
            result = LEDClient.LED_MakeRoot(nLEDID, "ROOT_PLAY", "COLOR_MODE_DOUBLE", "SURVIVE_ALWAYS");
            int num = System.Convert.ToInt32(result);
            LEDClient.LED_AddChapter(nLEDID, num, 30000, "WAIT_CHILD");
            LEDClient.LED_AddRegion(nLEDID, num, 0, 0, 128, 32, 0);


            //第1页面
            LEDClient.LED_AddLeaf(nLEDID, num, 10000, "WAIT_CHILD");
            //自动换行的文字
            //LEDClient.LED_AddTextEx(nLEDID, num, 0, 0, 128, 32, 1, 0, "Hello world! HELLO WORLD!", "宋体", 21, 0xff, "WFS_NONE", 0, 0, 0, 0, 6, 5, 1, 5, 0, 0, 3000);
            //非自动换行的文字
            //LEDSender.Do_AddTextEx(K, 0, 16, 64, 32, LEDSender.V_TRUE, 0, "Hello world! Hello world! Hello World!", "宋体", 12, 0xff00, LEDSender.WFS_NONE, LEDSender.V_FALSE, 0, 0, 0, 7, 5, 1, 5, 0, 0, 3000);
            LEDClient.LED_AddTextEx(nLEDID, num, 0, 0, 128, 32, 1, 0, "Hello world! HELLO WORLD!", "FONT_SET_16", 21, 0xff, "WFS_NONE", 0, 0, 0, 0, 6, 5, 1, 5, 0, 0, 3000);
            LEDClient.LED_AddLeaf(nLEDID, num, 10000, "WAIT_CHILD");
            LEDClient.LED_AddTextEx(nLEDID, num, 0, 0, 128, 32, 1, 0, "Hello world! HELLO WORLD!", "FONT_SET_24", 21, 0xff00, "WFS_NONE", 0, 0, 0, 0, 6, 5, 1, 5, 0, 0, 3000);
            LEDClient.LED_SendToScreen(nLEDID, num, 1);
        }

        private void btnDateTime_Click(object sender, EventArgs e)
        {
            string text = "";
            int K = 0;
            Log = "Start data";
            result = LEDClient.LED_MakeRoot(nLEDID, "ROOT_PLAY", "COLOR_MODE_DOUBLE", "SURVIVE_ALWAYS");
            K = System.Convert.ToInt32(result);
            x = 0; y = 0; width = 128; height = 32;
            uint time = 1000;
            font = LEDClient.LED_GetFont(1);
            LEDClient.LED_AddChapter(nLEDID, K, 20 * time, "WAIT_CHILD");
            x = 0; y = 16; width = 80; height = 32;
            LEDClient.LED_AddRegion(nLEDID, K, x, y, width, height, 0);
            LEDClient.LED_AddLeaf(nLEDID, K, 2 * time, "WAIT_CHILD");
            LEDClient.LED_AddDateTimeEx(nLEDID, K, x, y, width, height, 1, 0, 0, font, 12, 0xffff, "WFS_NONE", 0, 0, 0, 0, "#y-#m-#d");
            /*
            x = 40; y = 20; width = 80; height = 32;
            LEDClient.LED_AddRegion(nLEDID, K, x, y, width, height, 0);
            LEDClient.LED_AddDateTimeEx(nLEDID, K, x, y, width, height, 1, 0, 1, font, 12, 0xff, "WFS_NONE", 0, 0, 0, 0, "#y-#m-#d");
           */
            x = 0; y = 0; width = 256; height = 32;      //第1页面
            LEDClient.LED_AddRegion(nLEDID, K, x, y, width, height, 0);
            LEDClient.LED_AddLeaf(nLEDID, K, 5 * time, "WAIT_CHILD");
            LEDClient.LED_AddClockEx2(nLEDID, K, x, y, width, height, 1, 0, 0, 0, 0x0, 0xfff, 1, "SHAPE_ROUNDRECT", 30, 3, 0xff00, 2, 0xffff, 0, 1, 0xff, 3, 0xffff, 2, 0xff00, 1, 0xff);
            LEDClient.LED_SendToScreen(nLEDID, K, 1);
        }

        private void btnCountUp_Click(object sender, EventArgs e)
        {

            ushort K;
            TTimeStamp basetime = new TTimeStamp();
            TSystemTime T = new TSystemTime();
            DateTime dtNow = System.DateTime.Now;

            result = LEDClient.LED_MakeRoot(nLEDID, "ROOT_PLAY", "COLOR_MODE_DOUBLE", "SURVIVE_ALWAYS");
            int num = System.Convert.ToInt32(result);
            LEDClient.LED_AddChapter(nLEDID, num, 30000, "WAIT_CHILD");
            LEDClient.LED_AddRegion(nLEDID, num, 0, 0, 128, 32, 0);



            LEDClient.LED_AddLeaf(nLEDID, num, 10000, "WAIT_CHILD");


            EncodeDateTime(ref T, (ushort)dtNow.Year, (ushort)dtNow.Month, (ushort)dtNow.Day, 1, 0, 0, 0);
            SystemTimeToTimeStamp(ref T, ref basetime);

            LEDClient.LED_AddCounter(nLEDID, num, 0, 0, 128, 32, 1, 0, "CT_COUNTUP", "CF_HNS", "Times New Roman", 12, 0xff, "WFS_NONE", basetime.time, basetime.date);

            EncodeDateTime(ref T, 1899, 1, 1, 1, 29, 0, 0);
            SystemTimeToTimeStamp(ref T, ref basetime);
            LEDClient.LED_AddCounter(nLEDID, num, 0, 10, 128, 32, 1, 0, "CT_COUNTUP", "CF_HNS", "Times New Roman", 12, 0xff, "WFS_NONE", basetime.time, basetime.date);
            LEDClient.LED_SendToScreen(nLEDID, num, 1);
        }
        private void btnClock_Click(object sender, EventArgs e)
        {


        }
        private void btnCountDown_Click(object sender, EventArgs e)
        {

            ushort K;
            TTimeStamp basetime = new TTimeStamp();
            TSystemTime T = new TSystemTime();
            DateTime dtNow = System.DateTime.Now;

            result = LEDClient.LED_MakeRoot(nLEDID, "ROOT_PLAY", "COLOR_MODE_DOUBLE", "SURVIVE_ALWAYS");
            int num = System.Convert.ToInt32(result);
            LEDClient.LED_AddChapter(nLEDID, num, 30000, "WAIT_CHILD");
            LEDClient.LED_AddRegion(nLEDID, num, 0, 0, 128, 32, 0);



            LEDClient.LED_AddLeaf(nLEDID, num, 10000, "WAIT_CHILD");


            EncodeDateTime(ref T, (ushort)dtNow.Year, (ushort)dtNow.Month, (ushort)dtNow.Day, 1, 0, 0, 0);
            SystemTimeToTimeStamp(ref T, ref basetime);

            LEDClient.LED_AddCounter(nLEDID, num, 0, 0, 128, 32, 1, 0, "CT_COUNTDOWN", "CF_HNS", "Times New Roman", 12, 0xff, "WFS_NONE", basetime.time, basetime.date);

            EncodeDateTime(ref T, 1899, 1, 1, 1, 29, 0, 0);
            SystemTimeToTimeStamp(ref T, ref basetime);
            LEDClient.LED_AddCounter(nLEDID, num, 0, 10, 128, 32, 1, 0, "CT_COUNTDOWN", "CF_HNS", "Times New Roman", 12, 0xff, "WFS_NONE", basetime.time, basetime.date);
            LEDClient.LED_SendToScreen(nLEDID, num, 1);
        }

        private void btnCampaign_Click(object sender, EventArgs e)
        {

            ushort K;
            TTimeStamp basetime = new TTimeStamp();
            TTimeStamp fromtime = new TTimeStamp();
            TTimeStamp totime = new TTimeStamp();
            TSystemTime T = new TSystemTime();
            DateTime dtNow = System.DateTime.Now;

            result = LEDClient.LED_MakeRoot(nLEDID, "ROOT_PLAY", "COLOR_MODE_DOUBLE", "SURVIVE_ALWAYS");
            int num = System.Convert.ToInt32(result);
            LEDClient.LED_AddChapter(nLEDID, num, 30000, "WAIT_CHILD");
            LEDClient.LED_AddRegion(nLEDID, num, 0, 0, 128, 32, 0);

            LEDClient.LED_AddLeaf(nLEDID, num, 10000, "WAIT_CHILD");
            LEDClient.LED_AddDateTime(nLEDID, num, 0, 0, 128, 32, 1, 0, 0, "Times New Roman", 12, 0xffff, "WFS_NONE", 0, 0, 0, 0, "#y-#m-#d");


            //  2020-06-01 07:00:00
            EncodeDateTime(ref T, 2020, 6, 1, 7, 0, 0, 0);
            SystemTimeToTimeStamp(ref T, ref basetime);
            //  2012-05-02 09:00:00
            EncodeDateTime(ref T, 2012, 5, 2, 9, 0, 0, 0);
            SystemTimeToTimeStamp(ref T, ref fromtime);
            //  2012-05-02 10:00:00
            EncodeDateTime(ref T, 2012, 5, 2, 10, 0, 0, 0);
            SystemTimeToTimeStamp(ref T, ref totime);
            LEDClient.LED_AddCampaign(nLEDID, num, 0, 0, 128, 32, 1, 0, 0, "Times New Roman", 12, 0xffff, "WFS_NONE", "#y-#m-#d", basetime.time, basetime.date, fromtime.time, fromtime.date, totime.time, totime.date, 1000);
            LEDClient.LED_SendToScreen(nLEDID, num, 1);
        }



        private void btnChapter_Click(object sender, EventArgs e)
        {
            ushort K;
            /*
            K = (ushort)LEDSender.Do_MakeChapter(LEDSender.ROOT_PLAY_CHAPTER, LEDSender.ACTMODE_REPLACE, 0, LEDSender.COLOR_MODE_DOUBLE, 5000, LEDSender.WAIT_CHILD);
            LEDSender.Do_AddRegion(K, 0, 0, 128, 32, 0);
            LEDSender.Do_AddLeaf(K, 10000, LEDSender.WAIT_CHILD);
            LEDSender.Do_AddText(K, 0, 0, 64, 16, LEDSender.V_TRUE, 0, "Hello world! HELLO WORLD!", "宋体", 12, 0xff, LEDSender.WFS_NONE, LEDSender.V_TRUE, 0, 0, 1, 1, 1, 0, 1, 3);

            Parse(LEDSender.Do_LED_SendToScreen(ref param, K));
            */
        }

        private void btnRegion_Click(object sender, EventArgs e)
        {
            /*
            
            ushort K; 
         
            K = (ushort)LEDSender.Do_MakeRegion(LEDSender.ROOT_PLAY_REGION, LEDSender.ACTMODE_REPLACE, 0, 0, LEDSender.COLOR_MODE_DOUBLE, 0, 0, 128, 32, 0);
            LEDSender.Do_AddLeaf(K, 10000, LEDSender.WAIT_CHILD);
            LEDSender.Do_AddText(K, 0, 0, 64, 16, LEDSender.V_TRUE, 0, "Hello world! HELLO WORLD!", "宋体", 12, 0xff, LEDSender.WFS_NONE, LEDSender.V_TRUE, 0, 0, 1, 1, 1, 0, 1, 3);

            Parse(LEDSender.Do_LED_SendToScreen(ref param, K));
            */
        }

        private void btnLeaf_Click(object sender, EventArgs e)
        {


            ushort K;

            result = LEDClient.LED_MakeLeaf(nLEDID, "ROOT_PLAY_LEAF", "ACTMODE_REPLACE", 0, 3, 0, "COLOR_MODE_DOUBLE", 5000, "WAIT_CHILD");
            K = System.Convert.ToUInt16(result);
            LEDClient.LED_AddText(nLEDID, K, 0, 0, 64, 32, 1, 0, "WCF页面", "宋体", 12, 120, "WFS_NONE", 0, 0, 1, 0, 1, 0, 0, 0, 1000);
            Text = "开始发送数据";
            result = LEDClient.LED_SendToScreen(nLEDID, K, 0);
            Text = result;

        }
        private void btnObject_Click(object sender, EventArgs e)
        {

            ushort K;

            //这个操作中，ChapterIndex=0，RegionIndex=0，LeafIndex=0，ObjectIndex=0 只更新控制卡内第1个节目中的第1个分区中的第1个页面中的第1个对象
            //如果ChapterIndex=1，RegionIndex=2，LeafIndex=1，ObjectIndex=2只更新控制卡内第2个节目中的第3个分区中的第2个页面中的第3个对象
            //以此类推
            result = LEDClient.LED_MakeObject(nLEDID, "ROOT_PLAY_OBJECT", "ACTMODE_REPLACE", 0, 2, 0, 0, "COLOR_MODE_DOUBLE");
            K = System.Convert.ToUInt16(result);
            string text = LEDClient.LED_GetText(25);
            //LEDClient.LED_AddText(nLEDID,K, 0, 0, 128, 32, 1, 0, text, "宋体", 12, 0xffff, "WFS_NONE", 0, 0, 0, 5, 0, 5, 0, 1, 3);
            inmethod = 2;
            inspeed = 1;
            stoptime = 3;
            x = 0; y = 48; width = 288; height = 16;
            LEDClient.LED_AddText(nLEDID, K, 0, 0, 288, 16, 1, 0, text, "宋体", 12, 0xff00, "WFS_NONE", 0, 0, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime);
            Text = "开始发送数据";
            result = LEDClient.LED_SendToScreen(nLEDID, K, 0);
            Text = result;
        }
        private void btnOnlineServerStartup_Click(object sender, EventArgs e)
        {

        }

        private void btnOnlineServerCleanup_Click(object sender, EventArgs e)
        {
            //LEDSender.Do_LED_Report_RemoveServer(0);

        }

        private void btnOnlineGetList_Click(object sender, EventArgs e)
        {
            int devcount;
            int I;
            String S;


        }



        private void btnTimerTest_Click(object sender, EventArgs e)
        {
            if (timerMain.Enabled)
            {
                timerMain.Enabled = false;
                btnTimerTest.Text = "启动定时发送测试";
            }
            else
            {
                timerMain.Interval = 5000;
                timerMain.Enabled = true;
                btnTimerTest.Text = "停止定时发送测试";
            }
        }

        UInt32 serialno = 0;

        private void timerMain_Tick(object sender, EventArgs e)
        {

            ushort I, K;
            string text;

            for (I = 1; I <= 4; I++)
            {
                nLEDID = I;
                /*
                result = LEDClient.LED_MakeRoot(nLEDID, "ROOT_PLAY", "COLOR_MODE_DOUBLE", "SURVIVE_ALWAYS");
                int num = System.Convert.ToInt32(result);
                LEDClient.LED_AddChapter(nLEDID, num, 30000, "WAIT_CHILD");
                LEDClient.LED_AddRegion(nLEDID, num, 0, 0, 128, 32, 0);
                //第1页面
                LEDClient.LED_AddLeaf(nLEDID, num, 10000, "WAIT_CHILD");
                text = "IP=" + I + "\r\n" + "序列号=" + serialno;
                LEDClient.LED_AddText(nLEDID, num,0, 0, 128, 32, LEDSender.V_TRUE, 0, text, "宋体", 12, 0xff, "WFS_NONE", 1, 0, 1, 5, 1, 1, 0, 1, 3000);
                serialno++;                
                Text = "<" + param.devParam.rmtHost + ">正在发送数据...";
                LEDClient.LED_SendToScreen(nLEDID, num); 
                */
            }
        }



        private void btnBoardParam_Click(object sender, EventArgs e)
        {

            LEDClient.LED_Registration(3, "  ", "LED03", "192.168.0.101", "01-01-F1-DE-1A-02","DEVICE_TYPE_UDP","SBR_57600","8889","1","COLOR_MODE_DOUBLE","6666","255","256","32");
                 
        }
        public void StartUpAndShowIP(int nLEDID)
        {
            string ip = LEDClient.SwithPower(nLEDID, 1, 1);
            object result = LEDClient.LED_MakeRoot(nLEDID, "ROOT_DOWNLOAD", "COLOR_MODE_DOUBLE", "SURVIVE_ALWAYS");
            ushort K = System.Convert.ToUInt16(result);
            LEDClient.LED_AddChapter(nLEDID, K, 30000, "WAIT_CHILD");
            LEDClient.LED_AddRegion(nLEDID, K, 0, 0, 128, 32, 0);
            LEDClient.LED_AddLeaf(nLEDID, K, 10000, "WAIT_CHILD");
            LEDClient.LED_AddText(nLEDID, K, 0, 0, 128, 64, 1, 0, ip, "宋体", 12, 0xff, "WFS_NONE", 1, 0, 0, 1, 1, 1, 0, 1, 3);
            LEDClient.LED_SendToScreen(nLEDID, K, 1);
        }
        private void btnMultiCard_Click(object sender, EventArgs e)
        {/*
            TSenderParam param = new TSenderParam();
            ushort K;
            int x, y, cx, cy;

            GetDeviceParam(ref param.devParam);
            param.notifyMode = LEDSender.NOTIFY_BLOCK;
            param.wmHandle = (UInt32)Handle;
            param.wmMessage = WM_LED_NOTIFY;

            x = 0;
            y = 0;
            cx = 320;
            cy = 176;

            //----------------------------

            K = (ushort)LEDSender.Do_MakeRoot(LEDSender.ROOT_PLAY, LEDSender.COLOR_MODE_DOUBLE, LEDSender.SURVIVE_ALWAYS);

            LEDSender.Do_AddChapter(K, 1000, LEDSender.WAIT_USE_TIME);
            LEDSender.Do_AddRegion(K, x, y, cx, cy, 0);
            LEDSender.Do_AddLeaf(K, 1000, LEDSender.WAIT_CHILD);
            LEDSender.Do_AddText(K, x, y, cx, cy, LEDSender.V_TRUE, 0, "行人通过马路时，请注意安全。珍惜生命，严禁酒后驾车。开车时请您系好安全带。", "宋体", 24, 0xff, LEDSender.WFS_NONE, LEDSender.V_TRUE, 0, 1, 1, 1, 1, 0, 1, 3);

            LEDSender.Do_AddChapter(K, 1000, LEDSender.WAIT_USE_TIME);
            LEDSender.Do_AddRegion(K, x, y, cx, cy, 0);
            LEDSender.Do_AddLeaf(K, 1000, LEDSender.WAIT_CHILD);
            LEDSender.Do_AddText(K, x, y, cx, cy, LEDSender.V_TRUE, 0, "行人通过马路时，请注意安全。珍惜生命，严禁酒后驾车。开车时请您系好安全带。", "宋体", 24, 0xff00, LEDSender.WFS_NONE, LEDSender.V_TRUE, 0, 1, 1, 1, 1, 0, 1, 3);

            Text = "正在发送1...";
            param.devParam.rmtHost = "43.35.162.36";
            Parse2(LEDSender.Do_LED_SendToScreen(ref param, K));

            //----------------------------

            K = (ushort)LEDSender.Do_MakeRoot(LEDSender.ROOT_PLAY, LEDSender.COLOR_MODE_DOUBLE, LEDSender.SURVIVE_ALWAYS);

            LEDSender.Do_AddChapter(K, 1000, LEDSender.WAIT_USE_TIME);
            LEDSender.Do_AddRegion(K, x, y, cx, cy, 0);
            LEDSender.Do_AddLeaf(K, 1000, LEDSender.WAIT_CHILD);
            LEDSender.Do_AddText(K, x, y, cx, cy, LEDSender.V_TRUE, 0, "行人通过马路时，请注意安全。珍惜生命，严禁酒后驾车。开车时请您系好安全带。", "宋体", 24, 0xff, LEDSender.WFS_NONE, LEDSender.V_TRUE, 0, 1, 1, 1, 1, 0, 1, 3);

            LEDSender.Do_AddChapter(K, 1000, LEDSender.WAIT_USE_TIME);
            LEDSender.Do_AddRegion(K, x, y, cx, cy, 0);
            LEDSender.Do_AddLeaf(K, 1000, LEDSender.WAIT_CHILD);
            LEDSender.Do_AddText(K, x, y, cx, cy, LEDSender.V_TRUE, 0, "行人通过马路时，请注意安全。珍惜生命，严禁酒后驾车。开车时请您系好安全带。", "宋体", 24, 0xff00, LEDSender.WFS_NONE, LEDSender.V_TRUE, 0, 1, 1, 1, 1, 0, 1, 3);

            Text = "正在发送2...";
            param.devParam.rmtHost = "43.35.162.37";
            Parse2(LEDSender.Do_LED_SendToScreen(ref param, K));

            //----------------------------

            K = (ushort)LEDSender.Do_MakeRoot(LEDSender.ROOT_PLAY, LEDSender.COLOR_MODE_DOUBLE, LEDSender.SURVIVE_ALWAYS);

            LEDSender.Do_AddChapter(K, 1000, LEDSender.WAIT_USE_TIME);
            LEDSender.Do_AddRegion(K, x, y, cx, cy, 0);
            LEDSender.Do_AddLeaf(K, 1000, LEDSender.WAIT_CHILD);
            LEDSender.Do_AddText(K, x, y, cx, cy, LEDSender.V_TRUE, 0, "行人通过马路时，请注意安全。珍惜生命，严禁酒后驾车。开车时请您系好安全带。", "宋体", 24, 0xff, LEDSender.WFS_NONE, LEDSender.V_TRUE, 0, 1, 1, 1, 1, 0, 1, 3);

            LEDSender.Do_AddChapter(K, 1000, LEDSender.WAIT_USE_TIME);
            LEDSender.Do_AddRegion(K, x, y, cx, cy, 0);
            LEDSender.Do_AddLeaf(K, 1000, LEDSender.WAIT_CHILD);
            LEDSender.Do_AddText(K, x, y, cx, cy, LEDSender.V_TRUE, 0, "行人通过马路时，请注意安全。珍惜生命，严禁酒后驾车。开车时请您系好安全带。", "宋体", 24, 0xff00, LEDSender.WFS_NONE, LEDSender.V_TRUE, 0, 1, 1, 1, 1, 0, 1, 3);

            Text = "正在发送3...";
            param.devParam.rmtHost = "43.35.162.35";
            Parse2(LEDSender.Do_LED_SendToScreen(ref param, K));
            */
        }

        private void button1_Click(object sender, System.EventArgs e)
        {


            LEDClient.SwithPower(nLEDID, 1, 0);
        }

        private void button2_Click(object sender, System.EventArgs e)
        {
            char[] delimiterChars = { ';', ',', '.', ':', '\t' };

            string IPs = "1;2;3;4";
            System.Console.WriteLine("Original text: '{0}'", IPs);

            string[] led = IPs.Split(delimiterChars);
            foreach (string ip in led)
            {
                LEDClient.SwithPower(System.Convert.ToInt32(ip), 0, 0);
            }
            Log = IPs + " 关闭";
            MessageBox.Show("请查看消息");
            foreach (string ip in led)
            {
                LEDClient.SwithPower(System.Convert.ToInt32(ip), 1, 0);
            }
            Log = IPs + " 打开";

        }

        private void button4_Click(object sender, System.EventArgs e)
        {
            ushort K;

            result = LEDClient.LED_MakeChapter(nLEDID, "ROOT_PLAY_CHAPTER", "ACTMODE_REPLACE", 0, "COLOR_MODE_DOUBLE", 5000, "WAIT_CHILD");
            K = System.Convert.ToUInt16(result);
            LEDClient.LED_AddRegion(nLEDID, K, 0, 0, 256, 64, 0);
            LEDClient.LED_AddLeaf(nLEDID,K, 10000, "WAIT_CHILD");
            LEDClient.LED_AddText(nLEDID, K, 0, 0, 256, 64, 1, 0, "特别紧急消息", "宋体", 32, 120, "WFS_NONE", 0, 0, 2, 5, 1, 0, 1, 0, 1000);
            Text = "开始发送数据";
            result = LEDClient.LED_SendToScreen(nLEDID, K, 0);
            Text = result;
        }

        private void button5_Click(object sender, System.EventArgs e)
        {
            Test1();
        }

    }
}
